//
//  HEGoodsRecomCell.m
//  HealthFamily
//
//  Created by LOOK on 2020/10/25.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEGoodsRecomCell.h"

@interface HEGoodsRecomCell()

@property (weak, nonatomic) IBOutlet UIImageView *goodImageView;

@property (weak, nonatomic) IBOutlet UILabel *titleLb;
@property (weak, nonatomic) IBOutlet YYLabel *priceLb;

@end

@implementation HEGoodsRecomCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _titleLb.font = DYFont(16);
    _priceLb.font = DYFont(16);
    _titleLb.text = @"-";
    
    [_goodImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView);
        make.width.height.mas_offset(120);
    }];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodImageView.mas_bottom).mas_offset(5);
        make.right.left.equalTo(self.contentView);
    }];

    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    [_priceLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

    [_priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(0);
        make.right.left.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
    
    [_goodImageView hg_setAllCornerWithCornerRadius:6];
}

- (void)setModel:(HEGoodsModel *)model {
    _model = model;
    _titleLb.text = model.name;
    
    [_goodImageView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:IMAGE_NAMED(@"noImage")];
    
    NSDictionary *attributes = @{NSFontAttributeName:DYBlodFont(16), NSForegroundColorAttributeName: [UIColor blackColor]};
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"￥%@元/次", model.Kprice] attributes:attributes];
    
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:[NSString stringWithFormat:@"￥%@", model.Kprice]] color:KHexColor(@"#FF5757") backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
    }];
    _priceLb.attributedText = text;
}


//-(UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
//    [self setNeedsLayout];
//
//    [self layoutIfNeeded];
//
//    CGSize size = [self.contentView systemLayoutSizeFittingSize: layoutAttributes.size];
//
//    CGRect cellFrame = layoutAttributes.frame;
//
//    cellFrame.size.height= size.height;
//
//    layoutAttributes.frame= cellFrame;
//
//    return layoutAttributes;
//}

@end
